package com.zhuchang.self_rpc.test.client;


import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;

/**
 * @Author RenPu
 * @Date 2021/8/17 18:05
 * @Version 1.0
 * @Description:
 **/
public class RpcClientInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel cp) throws Exception {
        //实际编解码
        ChannelPipeline pipeline = cp.pipeline();

        //对请求对象进行编码RpcEncoder
//        pipeline.addLast(new RpcEncoder(RpcRequest.class));
//
//        //对响应对象进行解码
//        pipeline.addLast(new RpcDencoder(RpcResponse.class));

        //netty提供的编码器处理，65336：整个数据包的大小设置，0：起始，4：包头
        pipeline.addLast(new LengthFieldBasedFrameDecoder(65336, 0, 4, 0, 0));


        //实际业务处理器RpcClientHandler
        pipeline.addLast(new RpcClientHandler());

    }
}
